<template>
	<form catchsubmit="formSubmit" catchreset="formReset">
		<view class="">
			<view class="body">
				<view class="top"><text>居民信息</text></view>
				<view class="room">
					<text>楼栋房号</text>
					<select name="" id="" v-model="houseid">
						<option value="">请选择楼栋信息</option>
						<option value="1" v-for="item in buildinglist">{{ item.name }}</option>
					</select>
				</view>
				<view class="name">
					<text>姓名</text>
					<input type="text" v-model="name" value="" placeholder="请填写姓名" />
				</view>
				<view class="identity">
					<text>身份证号</text>
					<input type="text" v-model="cardid" value="" placeholder="请填写身份证号" />
				</view>
				<view class="sex">
					<text>性别</text>
					<select name="" id="" v-model="sex">
						<option value="">请选择楼性别</option>
						<option value="1">男</option>
						<option value="2">女</option>
					</select>
				</view>
				<view class="tel">
					<text>联系电话</text>
					<input type="text" value="" v-model="mobile" placeholder="请填写联系电话" maxlength="11" />
				</view>
				<button type="default" @click="formSubmit">提交</button>
			</view>
		</view>
	</form>
</template>



<script>
	import request from '../../utils/request.js'
	import {buildinglist,useradd} from '../../api/userinfo.js'
	export default{
		data(){
			return{
				buildinglist:[],
				houseid:'',
				name:'',
				cardid:'',
				sex:'',
				mobile:''
			}
		},
		onLoad() {
			this.getbuildinglist()
		},
		methods:{
			async getbuildinglist(){
				let data = await buildinglist();
				console.log(data)
				this.buildinglist = data.data.list
			},
			async formSubmit(){
				let {res,errCode} = await useradd({
					houseid:this.houseid,
					name:this.name,
					cardid:this.cardid,
					sex:this.sex,
					mobile:this.mobile
				})
				if(errCode=='10000'){
					 uni.showToast({
					     title: '添加成功',
					     duration: 2000
					 });
				}
				console.log(res)
			}
		}
	}

</script>

<style>
@import './../../static/style/userinfo.less';
</style>
